#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QUuid>
#include <QPixmap>
#include <QDate>
#include <QStyle>
#include <QDialog>
#include <QMessageBox>
#include <QApplication>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowIcon(QIcon(":/baixinlogo.png"));
    setAutoFillBackground(true);
    setBackgroundRole(QPalette::BrightText);
    setAutoFillBackground(false);//fix linux black screen issue
    ui->textBrowser->setFrameStyle(QFrame::WinPanel|QFrame::Plain);
    setWindowTitle("安徽百信GUID生成器");
    updateuuid();

    //QImage* img=new QImage;
    //img->load(":/100trust.bmp");
    ui->label->setPixmap(QPixmap(":/100trust.bmp"));
    ui->label->setScaledContents(true);
    ui->label->setWhatsThis("安徽百信");

    connect(ui->pushButton,&QPushButton::clicked,this,&MainWindow::updateuuid);
    connect(ui->actionAbout_A,&QAction::triggered,[=](){
               QMessageBox box;
               box.setWindowIcon(QIcon(":/baixinlogo.png"));
               box.setWindowTitle(tr("关于"));
               box.setIcon(QMessageBox::NoIcon);
               QDate date(QDate::currentDate());
               box.setText(QString("\nCopyright © 2022-%1.All rights reserved.\n安徽百信信息有限公司 版权所有\n").arg(date.year()));
               box.exec();

    });

    connect(ui->actionupdate,&QAction::triggered,[=](){
             ui->pushButton->click();
    });

    connect(ui->actioncopy,&QAction::triggered,[=](){
           ui->pushButton_2->click();
    });

    connect(ui->actionclear,&QAction::triggered,[=](){
           ui->pushButton_3->click();
    });

}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::updateuuid(){

    QUuid uuid = QUuid::createUuid();
    QString struuid = uuid.toString().toUpper();
    QString struuidtemp = struuid;
    QStringList list = struuid.remove("{").split("-");

    ui->textBrowser->copyAvailable(true);
    ui->textBrowser->clear();
    ui->textBrowser->setText("Default Format");
    ui->textBrowser->append(struuidtemp.remove("{").remove("}").remove("-"));
    ui->textBrowser->append("\n");

    ui->textBrowser->append("Registry Format");
    ui->textBrowser->append(QString("{%1").arg(struuid));
    ui->textBrowser->append("\n");

    ui->textBrowser->append("Static Const Struch GUID:");
    ui->textBrowser->append(QString("{0x%1,0x%2,0x%3},{0x%4,0x%5,0x%6,0x%7,0x%8,0x%9,0x%10,0x%11}").arg(list[0])\
                            .arg(list[1]).arg(list[2]).arg(list[3].left(2)).arg(list[3].right(2)).arg(list[4].left(2))\
                            .arg(list[4].left(4).right(2))\
                            .arg(list[4].left(6).right(2))\
                            .arg(list[4].left(8).right(2))\
                            .arg(list[4].left(10).right(2))\
                            .arg(list[4].left(12).right(2))\
                            );
    ui->textBrowser->append("\n");

    ui->textBrowser->append("Define GUID");
    ui->textBrowser->append(QString("0x%1,0x%2,0x%3,0x%4,0x%5,0x%6,0x%7,0x%8,0x%9,0x%10,0x%11").arg(list[0])\
                            .arg(list[1]).arg(list[2]).arg(list[3].left(2)).arg(list[3].right(2)).arg(list[4].left(2))\
                            .arg(list[4].left(4).right(2))\
                            .arg(list[4].left(6).right(2))\
                            .arg(list[4].left(8).right(2))\
                            .arg(list[4].left(10).right(2))\
                            .arg(list[4].left(12).right(2))\
                            );
    ui->textBrowser->append("\n");


}

void MainWindow::on_actionquit_triggered()
{
    qApp->quit();
}


void MainWindow::on_pushButton_2_clicked()
{
    ui->textBrowser->selectAll();
    ui->textBrowser->copy();

}


void MainWindow::on_pushButton_3_clicked()
{
    ui->textBrowser->clear();
}

